<?php

	include_once("include/config.php");
	include_once("include/auth.lib.php");
	include_once("include/functions.php");

	$filter_field = $_POST["qtype"];
	$filter_value = $_POST["query"];
	
	if ($filter_value != '') {
		$filter = "WHERE UPPER($filter_field) LIKE '%". strtoupper($filter_value) . "%'";
	} else {
		$filter = "WHERE 1 = 1";
	}
	
	$sql = "SELECT id, nome, codice_federale, istruttore, email, sito
			  FROM palestre
             $filter 			  			  
			 ORDER BY nome";
	$result = runSQL($sql);
	
	$page = 1;
	$total = mysql_num_rows($result);
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	while ($row = mysql_fetch_assoc($result)) {
		$data['rows'][] = array(
			'id' => $row['id'],
			'cell' => array($row['id'], $row['nome'], $row['codice_federale'], $row['istruttore'], $row['email'], $row['sito'])
		);
	}
	
	echo json_encode($data);

?>